<?php
ksort($_POST); //排序post参数
reset($_POST); //内部指针指向数组中的第一个元素
$sign = '';
foreach ($_POST AS $key => $val) {
    if ($val == '') continue; //跳过空值
    if ($key != 'sign') { //跳过sign
        $sign .= "$key=$val&"; //拼接为url参数形式
    }
}
if (!$_POST['pay_no']||md5(substr($sign, 0, -1) . "1Y94JHAYA4rvjtYaf0ySBhCGd8AXudRO") != $_POST['sign']) { //KEY密钥为你的密钥
  //不合法的数据 不做处理
   exit('fail');
}else{ //合法的数据
    //业务处理
  
   		$str = "交易成功！订单号：".$_POST['pay_id'];
       file_put_contents("successchong.txt",$str."\r\n \r\n", FILE_APPEND);

       $ReturnArrays = array(
            "out_trade_no" => $_POST['pay_id'], 
            "amount" =>  $_POST['money']
        );  

       $notif_Url = "http://".$_SERVER['HTTP_HOST']."/index.php?m=Wap&c=Pay&a=newpay_notify2&donow=yes";//回调地址
      
      $calresult=callRequestCheck($notif_Url,$ReturnArrays);
      
      //file_put_contents("success.txt",$calresult."\r\n \r\n", FILE_APPEND);
      
        if($calresult == "success"){
            echo "success";
        }else{
            echo "NO";
        }
  
  
   // $_POST['pay_id'] 这是付款人的唯一身份标识或订单ID
   // $_POST['pay_no'] 这是流水号 没有则表示没有付款成功 流水号不同则为不同订单
   // $_POST['money'] 这是付款金额
   //  $_POST['param'] 这是自定义的参数
   //exit('success');
}
  
  function callRequestCheck($Url,$postData) {
            $curl = curl_init();
            curl_setopt($curl, CURLOPT_URL, $Url);
            curl_setopt($curl, CURLOPT_HEADER, 0);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
            $Data = curl_exec($curl);
            curl_close($curl);
            //$Data = json_decode($Data, true);
            return $Data;
        }

?>